import 'package:dio/dio.dart';
import 'package:mall/core/models/reg_new_qr.dart';
import 'package:mall/core/services/auth.dart';
import 'package:mall/core/providers/view_model.dart';

class RegNewQrModel extends ViewModel {
  final Auth auth;
  String _errorMessage;
  RegNewQr _data;

  RegNewQrModel(this.auth) : super();

  String get errorMessage => _errorMessage;

  RegNewQr get data => _data;

  Future<ViewState> regNewQr(String encodedClientId, String invitedCode) async {
    viewState = ViewState.busy;
    try {
      _data = await auth.regNewQr(encodedClientId, invitedCode);
      viewState = ViewState.success;
    } catch (e) {
      _errorMessage = e is DioError ? e.message : e.toString();
      viewState = ViewState.error;
    }
    return viewState;
  }
}
